<?php
namespace app\miniapp\controller\v1;

use app\common\controller\Api;
use app\miniapp\model\GoodsAttachModel;
use app\miniapp\model\GoodsModel;

/*
 * 与商品有关的操作，都写在这个控制器
 */
class  Goods extends Api
{
    protected $noNeedLogin = '*';

    // 查看商品详情
    public function detail()
    {
        $goodsId = input('goods_id');

        if (!$goodsId) {
            $this->error('参数错误，缺少商品ID参数！');
        }

        $goods = GoodsModel::where('id', $goodsId)->find();

        $images = GoodsAttachModel::where('goods_id', $goodsId)->field('url')->select();
        $goods['images'] = array_column($images, 'url');

        $this->success('商品详情', $goods);


    }
}